package com.muyan.singleton.v2;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * @Author: YLTDMenglc
 * @Date: 2019/6/11
 * @Time: 13:28
 * @Description:
 */
public class TestSingleton2 {

    public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
//        Sinleton2 sinleton1 = Sinleton2.getSinleton();
//        Sinleton2 sinleton2 = Sinleton2.getSinleton();
//        System.out.println(sinleton1 == sinleton2);
//        for(int i = 0;i<100;i++){
//            new Thread(new Runnable() {
//                @Override
//                public void run() {
//                    Sinleton2 sinleton = Sinleton2.getSinleton();
//                    System.out.println(Thread.currentThread().getName() +"," + sinleton);
//                }
//            }).start();
//        }

        Sinleton2 sinleton = Sinleton2.getSinleton();

        Constructor<Sinleton2> declaredConstructor = Sinleton2.class.getDeclaredConstructor();
        declaredConstructor.setAccessible(true);
        Sinleton2 sinleton2 = declaredConstructor.newInstance();

        System.out.println(sinleton == sinleton2);

    }
}
